<!--
 * @Description: <
 * @Author: charles
 * @Date: 2021-07-02 10:38:40
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-07-07 22:32:03
-->
<template>
  <div class="list_container">
    <!-- 头部 -->
    <Header></Header>
    <!-- 文章列表 -->
    <div class="list">
      <!-- 文章 -->
      <div class="article" v-for="a in articles.list" :key="a.id">
        <div class="article_pic">
          <img :src="a.cover" alt="" />
        </div>
        <div class="article_info">
          <div>{{ a.title }}</div>
        </div>
      </div>
    </div>
    <!-- 文章列表 -->
    <Footer></Footer>
  </div>
</template>
<script>
import { get } from "../utils/request";
import Header from "./components/Header";
import Footer from "./components/Footer";
export default {
  data() {
    return {
      articles: {}, // 分页数据
      param: {
        page: 1,
        pageSize: 10,
      },
    };
  },
  watch: {
    $route: {
      // 亲测有效,我是用来监听query参数变化
      handler() {
        this.loadArticles();
      },
      deep: true,
    },
  },
  components: { Header, Footer },
  methods: {
    loadArticles() {
      let categoryId = this.$route.query.categoryId;
      this.param.categoryId = categoryId;
      let url = "/index/article/pageQuery";
      get(url, this.param).then((resp) => {
        this.articles = resp.data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.list_container {
  .list {
    min-height: 800px;
    width: 90%;
    margin: 0 auto;
    .article {
      margin-bottom: 1em;
      padding: 1em 0;
      & > div {
        height: 200px;
      }
      .article_pic {
        width: 300px;
        overflow: hidden;
        float: left;
        img {
          width: 100%;
        }
      }
      .article_info {
        margin-left: 320px;
      }
    }
  }
}
</style>